var Skink; if (!Skink) Skink = {};

/***********
Skink.Prefs
************/
if (!Skink.Prefs) Skink.Prefs = {};

Skink.Prefs.defaultPreferences = {
    'usemarkdown':              true,

    'window-x':                     50,
    'window-y':                     50,
    'window-width':                 275,
    'window-height':                600,
    'window-alpha':                 100,
    'window-hideafterdelay':        true,
    'window-restoreonupdates':      true,
    'window-minimizetosystray':     true,
    'window-minimizeatstartup':     false,
    'window-minimizeonbackground':  false,
    'window-restoreonactivate':     true,

    'window-showcontextmenus':  true,
    'window-tooltiphidedelay':  8000,
    'window-tooltipdelay':      500,
    'window-dropshadow':        true,

    'theme-basetheme':          'Spaz',

    'sound-enabled':            true,

    'network-refreshinterval':              300000,
    'network-autoadjustrefreshinterval':    true,
    'network-airhandlehttpauth':            false,

    'debug-enabled':            false,

    'sound-update':             '/assets/sounds/TokyoTrainStation/CSnd.mp3',
    'sound-new':                '/assets/sounds/TokyoTrainStation/New.mp3',

    'timeline-scrollonupdate':  false,
    'timeline-loadonstartup':   false,
    'timeline-keyboardnavwrap': false,

    'search-maxhits':           5,
    'search-query':             'spaz',
    'search-base-lang':         'en',

    'screennames-cache-max':    150,

    'checkupdate':              true,
    'checkupdate-testversions': false,

    'url-shortener':            'short.ie',

    'twitter-api-base-url':     API_BASE_URL,
    'twitter-base-url':         SERVICE_BASE_URL,

    'twitter-source':           'spaz',

    'twitter-disable-direct-posting':       false,

    'entryboxhint':             "What are you doing?",

    'key-toggle':               "+F",
    'key-newEntry':             "+T",
    'key-reply':                "+Shift+@",
    'key-reloadTimeline':       "Shift+F5",
    'key-showShortenWindow':    "+Shift+A",
    'key-highlight-code':       "+R"
}

// this maps methods to pref keys that should be
// called when they are changed
/*
    the methods:
    setUI: sets the exposed prefs UI for this preference
    onChange: things to execute when the value of this pref changes (like, say, changing the opacity of the window)
    check: make sure the current value is a "sane" one, within reasonable limits or a proper boolean, etc
    setFromUI: converts the UI value into the internally stored value, if needed (say, minutes into microseconds)
*/
Skink.Prefs.changeMethods = {
    'usemarkdown': {
        setUI: function(value) {
            $('#usemarkdown').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('usemarkdown', Boolean(Skink.Prefs.get('usemarkdown')))
        }
    },

    'window-x': {
        setUI: function(value) {},
        onChange: function(value) {},
        check: function() {}
    },
    'window-y': {
        setUI: function(value) {},
        onChange: function(value) {},
        check: function() {}
    },
    'window-width': {
        setUI: function(value) {},
        onChange: function(value) {},
        check: function() {}
    },
    'window-height': {
        setUI: function(value) {},
        onChange: function(value) {},
        check: function() {}
    },
    'window-alpha': {
        setUI: function(value) {
            $('#window-alpha').val(parseInt(value));
        },
        onChange: function(value) {
            //alert(percentage+"%");
            percentage = parseInt(value);
            if (isNaN(percentage)) {
                percentage = 100;
            }
            if (percentage < 25) {
                percentage = 25;
            }
            var val = parseInt(percentage) / 100;
            if (isNaN(val)) {
                val = 1;
            } else if (val >= 1) {
                val = 1;
            } else if (val <= 0) {
                val = 1;
            }

            /*  the bending code */
            BlenderEffect.get('app:/assets/blender/page.pbj',
            function(shader) {
                var tween = BlenderEffect.createShaderTransition(window.htmlLoader, shader, 1200, Tween.effects.elasticEase);
                tween.hideOnFinish = false;
                tween.start(true);
            });

            window.htmlLoader.alpha = val;
        },
        check: function() {
            var val = Skink.Prefs.get('window-alpha');
            if (val > 100) {
                Skink.Prefs.set('window-alpha', 100);
            } else if (val < 10) {
                Skink.Prefs.set('window-alpha', 10);
            }
        },
    },
    'window-hideafterdelay': {
        setUI: function(value) {},
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('window-hideafterdelay', Boolean(Skink.Prefs.get('window-hideafterdelay')))
        }
    },
    'window-restoreonupdates': {
        setUI: function(value) {},
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('window-restoreonupdates', Boolean(Skink.Prefs.get('window-restoreonupdates')))
        }
    },
    'window-minimizetosystray': {
        setUI: function(value) {
            $('#window-minimizetosystray').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('window-minimizetosystray', Boolean(Skink.Prefs.get('window-minimizetosystray')))
        }
    },
    'window-minimizeatstartup': {
        setUI: function(value) {
            $('#window-minimizeatstartup').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('window-minimizeatstartup', Boolean(Skink.Prefs.get('window-minimizeatstartup')))
        }
    },
    'window-minimizeonbackground': {
        setUI: function(value) {
            $('#window-minimizeonbackground').attr('checked', value);
        },
        onChange: function(value) {
            if (value) {
                air.NativeApplication.nativeApplication.addEventListener('deactivate',
                function() {
                    //window.nativeWindow.minimize();
                    Skink.Windows.windowMinimize();
                })
            }
        },
        check: function() {
            Skink.Prefs.set('window-minimizeonbackground', Boolean(Skink.Prefs.get('window-minimizeonbackground')))
        }
    },
    'window-restoreonactivate': {
        setUI: function(value) {
            $('#window-restoreonactivate').attr('checked', value);
        },
        onChange: function(value) {
            if (value) {
                air.NativeApplication.nativeApplication.addEventListener('activate',
                function() {
                    //window.nativeWindow.restore();
                    Skink.Windows.windowRestore();
                })
            }
        },
        check: function() {
            Skink.Prefs.set('window-restoreonactivate', Boolean(Skink.Prefs.get('window-restoreonactivate')))
        }
    },
    'window-dropshadow': {
        setUI: function(value) {
            $('#window-dropshadow').attr('checked', value);
        },
        onChange: function(value) {
            if (value) {
                window.htmlLoader.filters = window.runtime.Array(
                new window.runtime.flash.filters.DropShadowFilter(3, 90, 0, .8, 6, 6));
            } else {
                window.htmlLoader.filters = null;
            }
        },
        check: function() {
            Skink.Prefs.set('window-dropshadow', Boolean(Skink.Prefs.get('window-dropshadow')))
        }
    },
    'timeline-keyboardnavwrap': {
        setUI: function(value) {
            $('#timeline-keyboardnavwrap').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('timeline-keyboardnavwrap', Boolean(Skink.Prefs.get('timeline-keyboardnavwrap')))
        }
    },
    'theme-basetheme': {
        setUI: function(value) {
            $('#theme-basetheme').val(value);
        },
        onChange: function(value) {
            Skink.Themes.setCurrentTheme()
        }
    },

    'sound-enabled': {
        setUI: function(value) {
            $('#sound-enabled').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('sound-enabled', Boolean(Skink.Prefs.get('sound-enabled')))
        }
    },

    'twitter-base-urls': {
        setUI: function(value) {
            $('#twitter-base-urls').val(value);
        },
        onChange: function(value) {
            if (value) {

                switch (value) {

                case 'identica':
                    var baseurl = 'http://identi.ca/';
                    var apiurl = 'http://identi.ca/api/';
                    break;

                default:
                    var baseurl = SERVICE_BASE_URL;
                    var apiurl  = API_BASE_URL;
                    break;
                }
                Skink.Prefs.set('twitter-api-base-url', apiurl);
                Skink.Prefs.changeMethods['twitter-api-base-url'].setUI(apiurl);
                Skink.Prefs.set('twitter-base-url', baseurl);
                Skink.Prefs.changeMethods['twitter-base-url'].setUI(baseurl);
            }
        }
    },
    'twitter-api-base-url': {
        setUI: function(value) {
            Skink.dump('value:' + value);
            $('#twitter-api-base-url').val(value);
        },
    },
    'twitter-base-url': {
        setUI: function(value) {
            Skink.dump('value:' + value);
            $('#twitter-base-url').val(value);
        },

    },

    'twitter-disable-direct-posting': {
        setUI: function(value) {
            $('#twitter-disable-direct-posting').attr('checked', value);
        },
        check: function() {
            Skink.Prefs.set('twitter-disable-direct-posting', Boolean(Skink.Prefs.get('twitter-disable-direct-posting')));
        }
    },


    'search-maxhits': {
        setUI: function(value) {
            $('#search-maxhits').val(parseInt(value));
        },
        onChange: function(value) {},
        check: function() {
            if (parseInt(Skink.Prefs.get('search-maxhits')) < 5) {
                Skink.Prefs.set('search-maxhits', 5);
            }
            if (parseInt(Skink.Prefs.get('search-maxhits')) > 1000) {
                Skink.Prefs.set('search-maxhits', 1000);
            }
        }
    },
    'search-query': {
        setUI: function(value) {
            $('#search-query').val(value);
        },
        onChange: function(value) {},
        check: function() {}
    },
    'search-base-lang': {
        setUI: function(value) {
            $('#search-base-lang').val(value);
        },
        onChange: function(value) {},
        check: function() {}
    },

    'network-refreshinterval': {
        setUI: function(value) {
            $('#network-refreshinterval').val(parseInt(value) / 60000);

            var minutes = parseInt(value) / 60000;
            var refperhour = 60 / minutes;
            var numreqs = Math.ceil(refperhour * 3);

            $('#refreshRateInfoValue').text(numreqs.toString())
        },
        onChange: function(value) {},
        check: function() {
            var val = parseInt(Skink.Prefs.get('network-refreshinterval'));
            if (val < 2 * 60000) {
                Skink.Prefs.set('network-refreshinterval', 2 * 60000);
            }
        },
        setFromUI: function(value) {
            return value * 60000;
        }
    },
    'network-autoadjustrefreshinterval': {
        setUI: function(value) {
            $('#network-autoadjustrefreshinterval').attr('checked', value);
        },
        onChange: function(value) {
            Skink.dump('Setting Auto Adjust Refresh Interval to ' + value)
            window.htmlLoader.authenticate = value;
        },
        check: function() {
            Skink.Prefs.set('network-autoadjustrefreshinterval', Boolean(Skink.Prefs.get('network-autoadjustrefreshinterval')))
        }
    },
    'network-airhandlehttpauth': {
        setUI: function(value) {
            $('#network-airhandlehttpauth').attr('checked', value);
        },
        onChange: function(value) {
            Skink.dump('Setting HTTPAuth handling to ' + value)
            window.htmlLoader.authenticate = value;
        },
        check: function() {
            Skink.Prefs.set('network-airhandlehttpauth', Boolean(Skink.Prefs.get('network-airhandlehttpauth')))
        }
    },

    'timeline-scrollonupdate': {
        setUI: function(value) {
            $('#timeline-scrollonupdate').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('timeline-scrollonupdate', Boolean(Skink.Prefs.get('timeline-scrollonupdate')))
        }
    },

    'checkupdate': {
        setUI: function(value) {
            $('#checkupdate').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('checkupdate', Boolean(Skink.Prefs.get('checkupdate')))
        }
    },
    'checkupdate-testversions': {
        setUI: function(value) {
            $('#checkupdate-testversions').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('checkupdate-testversions', Boolean(Skink.Prefs.get('checkupdate-testversions')))
        }
    },

    'debug-enabled': {
        setUI: function(value) {
            $('#debug-enabled').attr('checked', value);
        },
        onChange: function(value) {},
        check: function() {
            Skink.Prefs.set('debug-enabled', Boolean(Skink.Prefs.get('debug-enabled')))
        }
    },

    'screennames-cache-max': {
        check: function() {
            var val = parseInt(Skink.Prefs.get('screennames-cache-max'));
            if (val > 150) {
                Skink.Prefs.set('screennames-cache-max', 150);
            }
        }
    }
}

/**
 * Initializes the preferences: sets prefs from Skink.Prefs.defaultPreferences, loads prefs file, and sets up the prefs UI
 */
Skink.Prefs.init = function() {
    /*
        WE NEED TO COPY THIS, NOT ASSIGN!!!!
    */
    Skink.Prefs.preferences = clone(Skink.Prefs.defaultPreferences);
    Skink.dump("defaultPreferences:" + Skink.Prefs.defaultPreferences);
    Skink.Prefs.loadPrefs();
    Skink.Prefs.initUI();
}

/**
 * Loads the preferences.json file. If this file does not exist, it creates a new file based on Skink.Prefs.defaultPreferences
 */
Skink.Prefs.loadPrefs = function() {
    var prefsFile = air.File.applicationStorageDirectory;
    prefsFile = prefsFile.resolvePath("preferences.json");

    var fs = new air.FileStream();

    if (prefsFile.exists) {
        fs.open(prefsFile, air.FileMode.READ);
        var prefsJSON = fs.readUTFBytes(prefsFile.size);
        Skink.dump(prefsJSON)
        var loadedpreferences = JSON.parse(prefsJSON);

        Skink.dump(Skink.Prefs.defaultPreferences);
        Skink.dump(loadedpreferences);

        for (key in loadedpreferences) {
            Skink.dump('Copying "' + key + '" from loaded prefs to current prefs');
            Skink.Prefs.preferences[key] = loadedpreferences[key];
            Skink.dump('"' + key + '":"' + Skink.Prefs.preferences[key] + '" (' + typeof(Skink.Prefs.preferences[key]) + ')');

            if (Skink.Prefs.changeMethods[key] && Skink.Prefs.changeMethods[key].check) {
                Skink.dump("Calling check on " + key);
                Skink.Prefs.changeMethods[key].check();
            }
        }
    } else {
        fs.open(prefsFile, air.FileMode.WRITE);
        fs.writeUTFBytes(JSON.stringify(Skink.Prefs.defaultPreferences));
        Skink.Prefs.preferences = clone(Skink.Prefs.defaultPreferences);
    }
    fs.close()

    Skink.Prefs.loadUsername();
    Skink.Prefs.loadPassword();
};

Skink.Prefs.initUI = function() {
    for (pkey in Skink.Prefs.preferences) {
        //Skink.dump(pkey);
        if (Skink.Prefs.changeMethods[pkey]) {
            if (Skink.Prefs.changeMethods[pkey].setUI) {
                Skink.Prefs.changeMethods[pkey].setUI(Skink.Prefs.get(pkey));
            }
            if (Skink.Prefs.changeMethods[pkey].onChange) {
                Skink.Prefs.changeMethods[pkey].onChange(Skink.Prefs.get(pkey));
            }
        }
        $('#username').val(Skink.Prefs.getUser());
        //Skink.dump('set #username val to'+$('#username').val());
        $('#password').val(Skink.Prefs.getPass());
    }

    $('#window-alpha').bind('change', Skink.Prefs.setFromUI);
    $('#usemarkdown').bind('change', Skink.Prefs.setFromUI);
    $('#window-minimizetosystray').bind('change', Skink.Prefs.setFromUI);
    $('#window-minimizeatstartup').bind('change', Skink.Prefs.setFromUI);
    $('#window-minimizeonbackground').bind('change', Skink.Prefs.setFromUI);
    $('#window-restoreonactivate').bind('change', Skink.Prefs.setFromUI);
    $('#window-dropshadow').bind('change', Skink.Prefs.setFromUI);
    $('#timeline-keyboardnavwrap').bind('change', Skink.Prefs.setFromUI);
    $('#theme-basetheme').bind('change', Skink.Prefs.setFromUI);
    $('#sound-enabled').bind('change', Skink.Prefs.setFromUI);
    $('#search-maxhits').bind('change', Skink.Prefs.setFromUI);
    $('#search-query').bind('change', Skink.Prefs.setFromUI);
    $('#search-base-lang').bind('change', Skink.Prefs.setFromUI);
    $('#checkupdate').bind('change', Skink.Prefs.setFromUI);
    $('#checkupdate-testversions').bind('change', Skink.Prefs.setFromUI);
    $('#network-refreshinterval').bind('change', Skink.Prefs.setFromUI);
    $('#network-airhandlehttpauth').bind('change', Skink.Prefs.setFromUI);
    $('#network-autoadjustrefreshinterval').bind('change', Skink.Prefs.setFromUI);
    $('#debug-enabled').bind('change', Skink.Prefs.setFromUI);
    $('#usemarkdown').bind('change', Skink.Prefs.setFromUI);
    $('#timeline-scrollonupdate').bind('change', Skink.Prefs.setFromUI);
    $('#twitter-base-urls').bind('change', Skink.Prefs.setFromUI);
    $('#twitter-api-base-url').bind('change', Skink.Prefs.setFromUI);
    $('#twitter-base-url').bind('change', Skink.Prefs.setFromUI);
    $('#twitter-disable-direct-posting').bind('change', Skink.Prefs.setFromUI);
};

Skink.Prefs.setFromUI = function(event) {
    // Skink.dump(JSON.stringify(event));
    // Skink.dump('event.srcElement.id='+event.srcElement);
    var id = event.srcElement.id

    Skink.dump("setFromUI - " + id)

    if (event.srcElement.tagName == "INPUT" && event.srcElement.type == "checkbox") {
        if ($('#' + id).attr('checked')) {
            var val = true;
        } else {
            var val = false;
        }
    } else {
        var val = $('#' + id).val();
    }

    // rewrite the incoming value if needed
    if (Skink.Prefs.changeMethods[id] && Skink.Prefs.changeMethods[id].setFromUI) {
        val = Skink.Prefs.changeMethods[id].setFromUI(val);
    }

    // set the preference
    Skink.Prefs.set(id, val);

    if (Skink.Prefs.changeMethods[id]) {
        if (Skink.Prefs.changeMethods[id].check) {
            Skink.dump("Calling check on " + id + " -- current val is " + Skink.Prefs.get(id));
            Skink.Prefs.changeMethods[id].check();
        }
        if (Skink.Prefs.changeMethods[id].setUI) {
            Skink.dump("Calling setUI on " + id + " -- current val is " + Skink.Prefs.get(id));
            Skink.Prefs.changeMethods[id].setUI(Skink.Prefs.get(id));
        }
        if (Skink.Prefs.changeMethods[id].onChange) {
            Skink.dump("Calling onChange on " + id + " -- current val is " + Skink.Prefs.get(id));
            Skink.Prefs.changeMethods[id].onChange(Skink.Prefs.get(id));
        }
    }
};

Skink.Prefs.savePrefs = function() {
    var jsonPrefs = JSON.stringify(Skink.Prefs.preferences, null, 4);
    Skink.dump(jsonPrefs);

    var prefsFile = air.File.applicationStorageDirectory;
    prefsFile = prefsFile.resolvePath("preferences.json");

    var fs = new air.FileStream();

    fs.open(prefsFile, air.FileMode.WRITE);
    fs.writeUTFBytes(JSON.stringify(Skink.Prefs.preferences));
    fs.close();

    Skink.Prefs.saveUsername();
    Skink.Prefs.savePassword();
};

Skink.Prefs.resetPrefs = function() {
    Skink.Prefs.preferences = clone(Skink.Prefs.defaultPreferences);
    Skink.Prefs.savePrefs();
};

Skink.Prefs.get = function(key) {
    // Skink.dump("Getting pref key '"+key+"'");
    // Skink.dump("Value is "+Skink.Prefs.preferences[key]);
    if (Skink.Prefs.preferences[key]) {
        return Skink.Prefs.preferences[key];
    } else {
        return false;
    }
};

Skink.Prefs.set = function(key, value) {
    //Skink.dump("Setting pref key '"+key+"'="+value);
    Skink.Prefs.preferences[key] = value;
};

Skink.Prefs.saveUsername = function() {
    if (Skink.Prefs.user) {
        Skink.dump('saving username: ' + Skink.Prefs.user);
        var bytes = new air.ByteArray();
        bytes.writeUTFBytes(Skink.Prefs.user);
        air.EncryptedLocalStore.setItem('twitter_username_1', bytes);
    }
};

Skink.Prefs.loadUsername = function() {
    Skink.dump('loading username');
    var storedValue = air.EncryptedLocalStore.getItem('twitter_username_1');
    if (storedValue) {
        Skink.Prefs.user = storedValue.readUTFBytes(storedValue.length);
        return Skink.Prefs.user;
    } else {
        Skink.dump('Username COULD NOT BE LOADED');
        return false;
    }
};

Skink.Prefs.savePassword = function() {
    if (Skink.Prefs.pass) {
        Skink.dump('saving password: ********');
        var bytes = new air.ByteArray();
        bytes.writeUTFBytes(Skink.Prefs.pass);
        air.EncryptedLocalStore.setItem('twitter_password_1', bytes);
    }
};

Skink.Prefs.loadPassword = function() {
    Skink.dump('loading password');
    var storedValue = air.EncryptedLocalStore.getItem('twitter_password_1');
    if (storedValue) {
        Skink.Prefs.pass = storedValue.readUTFBytes(storedValue.length);
        return Skink.Prefs.pass;
    } else {
        Skink.dump('Password COULD NOT BE LOADED');
        return false;
    }
};

Skink.Prefs.setPrefs = function() {
    // Skink.dump('Verifying password');
    Skink.Data.verifyPassword();
    // Skink.dump('saving Prefs');
    Skink.Prefs.savePrefs();
}

Skink.Prefs.setCurrentUser = function() {
    Skink.Prefs.user = $('#username').val();
    Skink.Prefs.pass = $('#password').val();

    Skink.dump('set new username and pass (' + Skink.Prefs.user + ')');

    Skink.Prefs.saveUsername();
    Skink.Prefs.savePassword();

    Skink.dump('saved data');
}

Skink.Prefs.setHandleHTTPAuth = function(state) {
    Skink.dump(state);
    if (state) {
        Skink.Prefs.handleHTTPAuth = 1
        window.htmlLoader.shouldAuthenticate = true;
    } else {
        Skink.Prefs.handleHTTPAuth = 0;
        window.htmlLoader.shouldAuthenticate = false;
    }
    Skink.dump(Skink.Prefs.handleHTTPAuth);
    Skink.dump(window.htmlLoader.shouldAuthenticate);
}

Skink.Prefs.setDebugEnable = function(state) {
    Skink.Debug.setEnable(state);
}

Skink.Prefs.checkRefreshPeriod = function(val) {
    val = parseInt(val);
    if (val < 1) {
        val = 1;
    } else if (val > 60) {
        val = 60;
    }
    // convert msecs to minutes
    Skink.Prefs.set('network-refreshinterval', val * 60000);
    //Skink.UI.setPrefsFormVal('prefs-refresh-interval', val);
}

Skink.Prefs.checkWindowOpacity = function(percentage) {
    //alert(percentage+"%");
    percentage = parseInt(percentage);
    if (isNaN(percentage)) {
        percentage = 100;
    }
    if (percentage < 25) {
        percentage = 25;
    }
    var val = parseInt(percentage) / 100;
    if (isNaN(val)) {
        val = 1;
    } else if (val >= 1) {
        val = 1;
    } else if (val <= 0) {
        val = 1;
    }

    window.htmlLoader.alpha = val;

    Skink.Prefs.set('window-alpha', percentage);
    // Skink.UI.setPrefsFormVal('prefs-opacity-percentage', Skink.Prefs.windowOpacity);
}

Skink.Prefs.setRateLimit = function(rateinfo, data) {
    Skink.dump(JSON.stringify(rateinfo));

    var limit = rateinfo.hourly_limit;
    var per_min = Math.ceil((60 / (limit / 3)));
    var per_ms = per_min * 60000;

    Skink.dump("per_min = " + per_min);
    Skink.dump("per_ms  = " + per_ms);

    Skink.UI.statusBar('Twitter says limit is ' + limit + '/hour. Will refresh every ' + per_min + ' min');

    Skink.Prefs.changeMethods['network-refreshinterval'].setUI(per_ms);

    Skink.Prefs.set('network-refreshinterval', per_ms);
    Skink.Section.friends.mincachetime = per_ms;
}

Skink.Prefs.getUser = function() {
    if (Skink.Prefs.user == 'false') {
        return '';
    }
    return Skink.Prefs.user;
}

Skink.Prefs.getPass = function() {
    if (Skink.Prefs.pass == 'false') {
        return '';
    }
    return Skink.Prefs.pass;
}

Skink.Prefs.getRefreshInterval = function() {
    return Skink.Prefs.get('network-refreshinterval');
}

Skink.Prefs.getHandleHTTPAuth = function() {
    return Skink.Prefs.get('network-airhandlehttpauth');
}

Skink.Prefs.getToggleKey = function() {
    return Skink.Prefs.get('key-toggle');
}